package com.study.utils;

import cn.hutool.core.io.FileUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.core.io.ClassPathResource;
import org.springframework.util.ResourceUtils;

import java.io.File;
import java.io.FileNotFoundException;
import java.nio.charset.StandardCharsets;

/**
 * @author zhuzi
 * 2023/9/9 20:28
 */
@Slf4j
public class SysUtils {
    /**
     * 加载文件内容
     *
     * @param fileName 文件路径
     * @return
     */
    public static String loadFile(String fileName) {
        String path = new ClassPathResource(fileName).getPath();
        return FileUtil.readString(path, StandardCharsets.UTF_8);
    }

    /**
     * 文件路径
     *
     * @param path 路径
     * @return {@link String}
     */
    public static String filePath(String path) {
        try {
            File file = ResourceUtils.getFile("classpath:" + path);
            return file.getAbsolutePath();
        } catch (FileNotFoundException e) {
            throw new RuntimeException(e);
        }
    }
}
